package com.company3.students;

import java.util.List;

public class delstudent {
    /**
     * 通过学号删除学生对象
     *
     * @param id 学号
     * @param listStudents
     */
    public static void deleteStudent(int id, List<student> listStudents) {
        // 遍历学生对象List
        for (student student : listStudents) {
            // 获取当前对象索引
            int index = listStudents.indexOf(student);
            // 如果当前对象id等于目标id
            if (id == student.getId()) {
                // 删除
                listStudents.remove(index);
                System.out.printf("%d删除成功\n", student.getId());
            }
        }
    }
}
